import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToMany,
  JoinTable,
  UpdateDateColumn,
} from 'typeorm'
import { User } from '../user/user.entity'

@Entity('roles')
export class Role {
  @PrimaryGeneratedColumn()
  public id: number

  @Column({ type: 'varchar', length: 100, comment: '角色名称' })
  public name: string

  @Column({ type: 'varchar', length: 100, comment: '角色标题' })
  public title: string

  @Column({ type: 'tinyint', comment: '状态:1启用0禁用', default: 1 })
  status: number

  @CreateDateColumn({ comment: '创建时间', name: 'create_date' })
  createDate: Date

  @UpdateDateColumn({ comment: '更新时间', name: 'update_date' })
  updateDate: Date

  @ManyToMany(() => User, (user) => user.roles)
  @JoinTable({ name: 'roles_users' })
  users: User[]
}
